package com.baidu.util;

/**
 * Created by mac on 2017/12/29.
 */
public class Page {
    //当前页
    private int cpage;
    //尾页
    private int totalPage;
    //首页
    private int startPage;
    //上一页
    private int prevPage;
    //下一页
    private int nextPage;
    //总数
    private int count;
    //分页单位
    private int pageSize;
    //构造器
    public Page(String cpage, int count, int pageSize){
        this.count=count;
        this.pageSize=pageSize;
        this.initTotalPage();
        this.initCpage(cpage);
        this.initprevPage();
        this.initnextPage();
        this.initStartPage();
    }
    //处理总页数
    public void initTotalPage(){
        this.totalPage=(count/pageSize)+(count%pageSize==0?0:1);
    }
    //处理当前页

    public void initCpage(String cpage2){
        if(cpage2==null||"".equals(cpage2)){
            cpage2="1";
        }
        int cpage3=Integer.parseInt(cpage2);

        if(cpage3<=1){
            cpage3=1;
        }
        if(cpage3>=totalPage){
            cpage3=totalPage;
        }
        this.cpage=cpage3;
    }

    //处理上一页
    public void initprevPage(){
        if(cpage<=1){
            this.prevPage=1;
        }else{
            this.prevPage=cpage-1;
        }
    }
    //处理下一页
    public void initnextPage(){
        if(cpage>=totalPage){
            this.nextPage=totalPage;
        }else{
            this.nextPage=cpage+1;
        }
    }

    //处理起始位置
    public void initStartPage(){
        int startPage = (cpage-1)*pageSize;
        if(startPage<=0){
            this.startPage=0;
        }else{
            this.startPage=startPage;
        }
    }


    public int getCpage() {
        return cpage;
    }
    public void setCpage(int cpage) {
        this.cpage = cpage;
    }
    public int getTotalPage() {
        return totalPage;
    }
    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }
    public int getStartPage() {
        return startPage;
    }
    public void setStartPage(int startPage) {
        this.startPage = startPage;
    }
    public int getPrevPage() {
        return prevPage;
    }
    public void setPrevPage(int prevPage) {
        this.prevPage = prevPage;
    }
    public int getNextPage() {
        return nextPage;
    }
    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }
    public int getCount() {
        return count;
    }
    public void setCount(int count) {
        this.count = count;
    }
    public int getPageSize() {
        return pageSize;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
}
